import { CCString, Component, Label, _decorator } from "cc";
import { App } from "../../App";

const { ccclass, property, executeInEditMode, disallowMultiple, requireComponent, menu } = _decorator;

@ccclass
@executeInEditMode
@requireComponent(Label)
@disallowMultiple
@menu("i18n/Label")
export class i18nLabel extends Component {
    @property({ visible: false })
    private i18nString: string = '';

    @property({ type: CCString, tooltip: '语言文件中的key' })
    get i18nKey() {
        return this.i18nString;
    }

    set i18nKey(value: string) {
        this.i18nString = value;
        App.i18n.setText(this.getComponent(Label),this.i18nString);
    }

    onLoad() {
        App.i18n.register(this);
        this.reset();
    }

    onDestroy() {
        App.i18n.unregister(this);
    }

    public reset(){
        this.i18nKey = this.i18nString;
    }
}